package com.lagou.nio;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @Classname MapByteBufferTest
 * @Description TODO
 * @Date 2020/7/24 13:02
 * @Created by pc
 */
public class MapByteBufferTest {

    public static void main(String[] args) throws IOException {

        RandomAccessFile rw = new RandomAccessFile("file1.txt", "rw");
        FileChannel channel = rw.getChannel();

        MappedByteBuffer map = channel.map(FileChannel.MapMode.READ_WRITE, 0, 10);

        map.put(0, (byte) 'B');
        map.put(3, (byte) 'X');

        channel.close();
        rw.close();

    }
}
